<!DOCTYPE html>
<html lang="zh">
<head>
<title>密码修改</title>
<{include file="public/header" /}>
</head>
<body ontouchstart>
<!--主体-->
<header class="wy-header">
  <div class="wy-header-icon-back"><span></span></div>
  <div class="wy-header-title">找回密码</div>
</header>
<div class="weui-content">
  <div class="weui-cells weui-cells_form wy-address-edit">
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">原密码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" name="opwd" type="password"   placeholder="输入原密码"></div>

    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">新密码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" name="pwd" type="password"   placeholder="请输入新密码"></div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">确认密码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" name="pwd2" type="password"   placeholder="请确认新密码"></div>
    </div>
    <div class="weui-cell weui-cell_vcode">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">验证码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" name="vcode" type="text" placeholder="请输入验证码"></div>
      <div class="weui-cell__ft" id="vcode"><img class="weui-vcode-img" src="<{:url('get_vcode')}>"></div>
    </div>
  <div class="weui-btn-area"><a href="javascript:submit();" class="weui-btn weui-btn_primary">确认修改</a></div>
</div>
</div>
<{include file="public/footer" /}>
<script>
  $(function () {
    $("#vcode").on('click',function () {
      resetVcode()
    });

  })
  function resetVcode(){
    $(".weui-vcode-img").attr('src',"<{:url('get_vcode')}>")
  }

  function submit(){
    var opwd = $("input[name='opwd']").val();
    var vcode = $("input[name='vcode']").val();
    var pwd = $("input[name='pwd']").val();
    var pwd2 = $("input[name='pwd2']").val();
    if (!vcode){
      return   $.alert('请输入图形验证码','温馨提示')
    }
    if (!opwd){
      return   $.alert('请填写原密码','温馨提示')
    }
    if (pwd.length<6 || pwd.length>16){
      return   $.alert('新密码仅支持6~16位字符串','温馨提示')
    }
    if (!pwd || pwd !==pwd2){
      return   $.alert('确认密码不一致','温馨提示')
    }

    bs_request("<{:url('pwd_change_p')}>",{
      pwd:pwd,
      pwd2:pwd2,
      opwd:opwd,
      vcode:vcode,
    },function (res) {
      resetVcode();
      if (!res){
        return $.alert('网络超时');
      }

      if (res.code==0){
        $.confirm('已成功修改，是否跳个人中心？',function () {
          location.href = "<{:url('/mall/user/index')}>"
        })
      }else {
        $.alert(res.msg)
      }
    });


  }
</script>
</body>
</html>
